import Vue from 'vue'
import Vuex from 'vuex'
import service from './service.js'
Vue.use(Vuex);
const store = new Vuex.Store({
  state: {
    coinRMB: {},
    codeConfig:{
      convertCode:[],
      signBaseCode:'',
      signCostAsset:0
    },
  },
  getters: {
    COINRMB:(state) => {
      return state.coinRMB;
    },
    CODECONFIG:(state)=>{
      return state.codeConfig;
    }
  },
  mutations: {
  },
  actions: {
    //初始化
    inits({
      state,
      dispatch
    }) {
      // 判断是否登录请求用户数据
      let loginTime = uni.getStorageSync('LOGIN_TIME');
      if (Number(loginTime) > new Date().getTime()) {
        let token = uni.getStorageSync('TOKEN');
        if (token) {
          
        }
      } else {
        uni.removeStorageSync('LOGIN_TIME');
        uni.removeStorageSync('TOKEN');
      }
      service.getUSDK().then(({
        data
      }) => {
        if (data.code == '100200') {
          for(let i in data.data){
            data.data[i] = data.data[i].replace('¥', '') * 1;
          }
          state.coinRMB = data.data;
        }
      })
      
      service.getAssetCode().then(({data})=>{
        if(data.code == '100200'){
          state.codeConfig = data.data;
        }
      })
    }
  }
})
store.dispatch('inits');
export default store
